import 'package:app_info/info/appsflyer.dart';
import 'package:flutter/cupertino.dart';
import 'package:get_it/get_it.dart';
import 'package:smartloan_mdc/extension/extension.dart';
import 'package:smartloan_mdc/res/theme.dart';
import 'package:sml_policies/locator/sml_policies.dart';
import 'api_address.dart';
import 'app_config.dart';

GetIt locator = GetIt.instance;

/// 注入依赖, 这样做的好处是，只需要实现接口，就能实现切换。依赖倒转原则
setupLocator() {
  // locator.registerLazySingleton<AppsflyerSdk>(() => AppsflyerSdk(AppsFlyerOptions(afDevKey: 'yFbZbrMQ7eoqbZ4BdAPN'))); // 弹窗
  // locator.registerSingleton<HttpManager>(HttpManager(
  //     [
  //       // DioCacheManager(CacheConfig(baseUrl: Address.host)).interceptor,
  //       ErrorInterceptors(),
  //       HeaderInterceptors(),
  //       // TokenInterceptors(),
  //       RequestInterceptors(),
  //       LogsInterceptors(),
  //       ResponseInterceptors(),
  //     ]
  // )); // 样式
  // debugPrint('isRegistered: ${locator.isRegistered<AppConfig>()}');
  if (!(locator.isRegistered<AppConfig>())) {
    locator.registerSingleton(AppConfig());
    locator.registerSingleton(ApiAddress());
    locator.registerSingleton(SmlPoliciesConfig(
      language: 'es',
      logEvent: (String event) {
        AppsFlyer().logEvent(event);
      },
      onToast: (String toast) {
        toast.toast();
      },
      mainColor: AppTheme.mainColor
    ));
  }

}
